package com.lagou.edu.test;


import java.util.Properties;
import java.util.concurrent.Executor;
import com.alibaba.nacos.api.NacosFactory;
import com.alibaba.nacos.api.PropertyKeyConst;
import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;

/**
 * @author caiwei
 * @date 2020-12-14 20:31
 */
public class ConfigExample {
    public static final String TEST_NAMESPACE = "94cc546c-1f5e-443a-8679-ed35dc1758e8";

    public static void main(String[] args) throws NacosException, InterruptedException {
        String serverAddr = "127.0.0.1:8848,127.0.0.1:8849,127.0.0.1:8850";
        String dataId = "server-config.yaml";
        String group = "DEFAULT_GROUP";
        Properties properties = new Properties();
        // nacos服务器地址，127.0.0.1:8848
        properties.put(PropertyKeyConst.SERVER_ADDR, serverAddr);
        // 配置中心的命名空间id
        properties.put(PropertyKeyConst.NAMESPACE, TEST_NAMESPACE);

        ConfigService configService = NacosFactory.createConfigService(properties);
        // 根据dataId、group定位到具体配置文件，获取其内容. 方法中的三个参数分别是: dataId, group, 超时时间
        String content = configService.getConfig(dataId, group, 5000);
        System.out.println(content);

    }
}
